﻿@using Website.CRUDServices
@using Location = Website.Models.Domain.Location
@using Profile = Website.CRUDServices.Profile
@using Region = Website.Models.Domain.Region
@{
    this.ViewBag.Title = "Ny Klynge";
    this.Layout = "~/Views/_Shared/_Layout.cshtml";
    var Regions = this.ViewData["Regions"] as List<Region>;
    var Locations = this.ViewData["Locations"] as List<Location>;
    var Profiles = this.ViewData["Profiles"] as List<Profile>;
    var ClusterStatusTypes = this.ViewData["ClusterStatusTypes"] as List<ClusterStatusType>;
    var ClusterMethodTypes = this.ViewData["ClusterMethodTypes"] as List<ClusterMethodType>;
    var Projects = this.ViewData["Projects"] as List<Project>;
    var errorMsg = new HtmlString(string.Empty);
    int counter = 0;
    if (this.ViewData["ErrorMessage"] != null)
    {
        errorMsg = this.ViewData["ErrorMessage"] as HtmlString;
    }

}

<script>
    //datepicker script
    $(function() {
        $("#datepicker").datepicker();
        $('#OwnerProjects').multiSelect();
    });
</script>

<script type="text/javascript">
    //toggle script toggles div with id = id
    function toggle(id) {
        if (document.getElementById(id).style.display == 'none' || document.getElementById(id).style.display == "") {
            document.getElementById(id).style.display = 'block';
        } else {
            document.getElementById(id).style.display = 'none';
        }
    }
</script>

@using (this.Html.BeginForm("NewCluster", "Cluster", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    <div class="error">
        @errorMsg
    </div>

    // *******************Cluster*************************
    // name
    <div class="formBullet">Navn på klynge</div>
    <input type="text" id="Name" name="Name" />
    
                // date
    <div class="formBullet">Dato</div>
    <input type="text" id="datepicker" name="Date" readonly="readonly" value=""/>

    // location
    <div class="formBullet">Lokation</div>
    <div class="formEntry">
        <select name="Location" id="Location">
            <option value="@Guid.Empty">Vælg en lokation</option>
            @foreach (Location loc in Locations)
            {
                <option value="@loc.ID">@loc.Name</option>
            }
        </select>
    </div>
    
        // national or international?
    <div class="formBullet">Hvad er projektet?</div>
    <div>
        <input type="radio" name="IsNational" value="National">Nationalt
        <input type="radio" name="IsNational" value="International">Internationalt
    </div>

            // ownerProjects chooser
    <div class="formBullet">Alle projekter tilknyttet</div>
    <div class="formEntry">
        <select multiple="multiple" name="OwnerProjects" id="OwnerProjects">
            @foreach (Project proj in Projects)
            {
                <option value="@proj.ID">@proj.Name</option>
            }
        </select>
    </div>

            // profiles chooser
    <div class="formBullet">Profiler</div>
    <div class="formEntry">
        <select multiple="multiple" name="Profiles" id="Profiles">
            @foreach (Profile prof in Profiles)
            {
                <option value="@prof.ID">@prof.Name</option>
            }
        </select>
        <script src="@Url.Content("jquery.multi-select.js")" type="text/javascript"> </script>
    </div>

            // *******************ClusterStatus*************************
    <div class="formBullet">Status</div>

    <br />
            foreach (ClusterStatusType cst in ClusterStatusTypes)
            {

<fieldset class="chosenFields">
        <legend>
            <input type="checkbox" onclick="@Html.Raw("toggle('" + cst.ID + "');")" name="ClusterStatus[@counter].Checked" value="true" />@cst.Name<br />
        </legend>
        <div class="formEntry open_hidden" id="@cst.ID">
            <!--guid-->
            <input type="hidden" name="ClusterStatus[@counter].Type" value="@cst.ID" />
            <!--active?-->
            <div class="formEntry">
                <input type="radio" name="ClusterStatus[@counter].IsActive" value="true">Aktiv
                <input type="radio" name="ClusterStatus[@counter].IsActive" value="false">Inaktiv
                <br />
                <i>(Husk at vælge aktiv/inaktiv - kun hvis Aktiv er valgt, vil den blive vist i listen)</i>
            </div>
            <!--comments-->
            <div class="formBullet">
                Kommentarer  til @cst.Name<br />
            </div>
            <div class="formEntry">
                <textarea name="ClusterStatus[@counter].Comments"></textarea>
            </div>
        </div>
    </fieldset>
                counter++;
            }

            counter = 0;

            // *******************ClusterMethod*************************
    <div class="formBullet">Metode</div>
        <br />
   
            foreach (ClusterMethodType cmt in ClusterMethodTypes)
            {
        <fieldset class="chosenFields">
        <legend>
            <input type="checkbox" onclick="@Html.Raw("toggle('" + cmt.ID + "');")" name="ClusterMethod[@counter].Checked" value="true" />@cmt.Name<br />
        </legend>
        <div class="formEntry open_hidden" id="@cmt.ID">
            <!--guid-->
            <input type="hidden" name="ClusterMethod[@counter].Type" value="@cmt.ID" />
            <!--comments-->
            <div class="formBullet">Kommentarer til @cmt.Name<br />
            </div>
            <div class="formEntry">
                <textarea name="ClusterMethod[@counter].Comments"></textarea>
            </div>
            <!--filechooser-->
            <div class="formBullet">Fil til arkivering<br />
            </div>
            <div class="formEntry">
                @Microsoft.Web.Helpers.FileUpload.GetHtml("ClusterMethod[" + counter + "].PostedFiles", 0, true, false, "Tilføj flere filer", "Vælg fil til arkivering")
            </div>
            <!--arkchive location-->
            <div class="formBullet">Fysisk arkiverings placering</div>
            <input type="text" id="Archive" name="ClusterMethod[@counter].ArchiveLocation" />
        </div>
    </fieldset>
                counter++;
            }

    <div class="buttonHolder">
        <input type="submit" value="Opret" />
    </div>
}

<script>


    $(function() {
        $('#Profiles').multiSelect();
    });
</script>

